import com.lagou.lagourocketmq.Main;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.UnsupportedEncodingException;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Main.class)
public class test01 {



    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Test
    public void test01() throws UnsupportedEncodingException {


        Message message = new Message("lagou_order","order123".getBytes("utf-8"));
        rocketMQTemplate.syncSend("lagou-order","order1");


    }

    @Test
    public void test02(){

        rocketMQTemplate.setMessageQueueSelector((List<MessageQueue> mqs, Message msg, Object arg)->{
            int queueNum = Integer.valueOf(String.valueOf(arg)) % mqs.size();
            System.out.println("队列id："+queueNum+" 消息:"+new String(msg.getBody()));
            return mqs.get(queueNum);
        });

    }

}
